<template>
    <div class="goods-list">
        <div class="goods-item" v-for="item in goodsList" :key="item.id" @click="getGoodsInfo(item.id)">
            <div class="goods-intro">
                <img :src="item.img_url">
                <h1 class="title">{{ item.titile }}</h1>
            </div>
            <div class="goods-info">
                <p class="price">
                    <span>￥&nbsp;{{ item.sell_price }}</span>
                    &nbsp;&nbsp;&nbsp;
                    <span><del>￥{{ item.market_price }}</del></span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{ item.stock_quantity }}件</span>
                </p>
            </div>
        </div>
        <mt-button type="danger" size="large" @click="getMoreGoods">加载更多</mt-button>
    </div>
</template>
<script>
    export default {
        data(){
            return {
                pageIndex: 1,
                goodsList: []
            }
        },
        created(){
            this.getGoodsList()
        },
        methods: {
            getGoodsList(){
                this.$http
                    .get('api/getgoods?pageindex=' + this.pageIndex)
                    .then(result => {
                        if (result.body.status === 0) {
                            this.goodsList.push(...result.body.message)
                        }
                    })
            },
            getMoreGoods(){
                this.pageIndex++;
                this.getGoodsList();
            },
            getGoodsInfo(id){
                this.$router.push({name: 'goodsinfo', params: {id: id}})
            }
        }
    }
</script>
<style lang="scss" scoped>
    .goods-list{
        margin: 0 auto;
        display:flex;
        justify-content: space-between;
        flex-wrap: wrap;
        padding: 10px;
        .goods-item{
            margin-bottom: 10px;
            width: 49%;
            box-shadow: 0 0 5px #ccc;
            border: solid 1px #ccc;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            .goods-intro{
                img{
                    min-height: 174px;
                    width: 100%;
                }
                .title{
                    margin: 0;
                    padding: 3px;
                    text-align: left;
                    font-size: 14px;
                    overflow: hidden
                }
            }
            .goods-info{
                background-color: rgba(204,204,204, .2);
                padding: 10px;
                span{
                    color: #ccc;
                    vertical-align: center;
                    font-size: 13px;
                }
                .price{
                    span{
                        color: red;
                        font-weight: bold;
                        font-size: 14px;
                    }
                    del{
                        color: #ccc;
                        font-size: 12px;
                        font-weight: normal;
                    }
                    
                }
                .sell{
                    margin: 0;
                    font-size: 12px;
                    display:flex;
                    justify-content: space-between;
                }
            }
        }
    }
</style>
